package com.example.compareprices;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.model.Shop;

public class AddShopActivity extends Activity {
	public static final String LOG_TAG = "AddShopActivity";
	private static final String EDIT = null;
	private EditText shopName, shopAddress;
	Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_shop);
		shopName = (EditText)findViewById(R.id.editText1);
		shopAddress = (EditText)findViewById(R.id.editText2);
		
		final Button buttAddOk = (Button) findViewById(R.id.button6);
		Bundle extras = getIntent().getExtras();
		String editMode = extras.getString(EDIT);
		if (editMode.equals("EDIT")){
			shopName.setText(extras.getString(Shop.NAME));
			shopAddress.setText(extras.getString(Shop.ADDRESS));
		}
		else{
			intent = new Intent();	
			intent.putExtra(Shop.NAME, "");
			intent.putExtra(Shop.ADDRESS, "");
			setResult(RESULT_OK, intent);
		}
		
		
		buttAddOk.setOnClickListener(new View.OnClickListener() {
			@Override
			//Adding new Shop
			public void onClick(View v) {
				
				intent.putExtra(Shop.NAME, shopName.getText().toString());
				intent.putExtra(Shop.ADDRESS, shopAddress.getText().toString());
				//Log.i(LOG_TAG, shopName.getText().toString());
				//Log.i(LOG_TAG, shopAddress.getText().toString());
				setResult(RESULT_OK, intent);
				finish();
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add_shop, menu);
		return true;
	}

}
